package com.lm.itextpdf.example;

import com.itextpdf.kernel.colors.Color;
import com.itextpdf.kernel.colors.DeviceRgb;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;

public class SetBackgroundColorExample {
    public static void main(String[] args) throws Exception {
        String dest = "background_example.pdf";

        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        Document document = new Document(pdfDoc);

        Color bgColor = new DeviceRgb(220, 220, 220);
        document.setBackgroundColor(bgColor);

        document.add(new Paragraph("This page has a background color."));
        document.close();

        System.out.println("PDF with background color created at: " + dest);
    }
}
